<template>
	<view class="questions">
		<u-navbar
			class="navbar_top"
			back-text="取消"
			title="提问"
			:title-size="36"
			:border-bottom="false"
			:back-icon-size="0"
			back-icon-color="#000000"
			:back-text-style="{ color: '#787882', fontSize: '26rpx' }"
		>
			<view class="navbar-right u-m-r-24" slot="right" @click="doissue">
				<text
					:style="{
						color: questions == '' ? '#787882' : '#FFDB28',
						fontWeight: questions == '' ? 100 : 600
					}"
				>
					发布问题
				</text>
			</view>
		</u-navbar>

		<view class="ipt">
			<u-input
				v-model="questions"
				:custom-style="{
					fontSize: '36rpx',
					textIndent: '30rpx'
				}"
				:height="150"
				type="textarea"
				placeholder="请输入问题 （5-49字）"
				:clearable="false"
				:maxlength="49"
			></u-input>
			<view class="lenght">
				{{ questions.length }}
				<text style="color: #dfdfdf;">/49</text>
			</view>
		</view>
		<view class="tips">
			<view class="top">一个好的提问:</view>
			<view class="tipst">·问题是什么，你想得到什么帮助，以"？"结尾</view>
			<view class="tipst">·你遇到的具体情况，以及是哪方面出现的问题？</view>
			<view class="tipst">·例：首单礼金客单价30以上， 红包是不是不减？</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
export default {
	name: 'questions',
	data() {
		return {
			questions: ''
		};
	},
	//实例创建完成后被立即调用
	created() {},
	onLoad(option) {},
	//挂载开始之前被调用
	beforeMount() {},
	// onPullDownRefresh() {
	// 	//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
	// 	console.log('refresh');
	// 	setTimeout(function() {
	// 		uni.stopPullDownRefresh(); //停止下拉刷新动画
	// 	}, 1000);
	// },
	//初次渲染完成
	onReady() {},
	//全局只触发一次
	onLaunch() {},
	//从后台进入前台
	onShow() {},
	//前台进入后台
	onHide() {},
	methods: {
		doissue() {
			console.log(this.questions);
			if (this.questions == '') {
				return;
			} else {
				this.$u.api
					.doaddproblem({
						q: this.questions
					})
					.then(res => {
						// console.log(res);
						this.$refs.uToast.show({
							title: '发布成功!',
							type: 'success'
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/knowledge/problem'
							});
						}, 300);
					})
					.catch(err => {
						console.log(err);
					});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.questions {
	.ipt {
		position: relative;
		.lenght {
			position: absolute;
			bottom: 0;
			right: 0;
		}
	}
	.tips {
		width: 662rpx;
		height: 218rpx;
		background-color: #f4f4f4;
		margin: 40rpx auto;
		padding: 20rpx 24rpx;
		font-size: 24rpx;
		border-radius: 16rpx;
		.top {
			font-weight: 600;
			color: #101010;
		}
		.tipst {
			color: #707070;
			line-height: 50rpx;
		}
	}
}
</style>
